home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
oper_sys
/
prospero
/
propsero.lha
/
prospero-beta.4.2e
/
user
/
vget.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-10
|
4KB
|
170 lines
/*
* Copyright (c) 1989, 1990, 1991 by the University of Washington
* Copyright (c) 1991, 1992 by the University of Southern California
*
* For copying and distribution information, please see the files
* <uw-copyright.h> and <usc-copyr.h>.
*/
#include <uw-copyright.h>
#include <usc-copyr.h>
#include <sys/param.h>
#include <sys/wait.h>
#include <strings.h>
#include <stdio.h>
#include <pfs.h>
#include <psite.h>
#include <perrno.h>
#include <pcompat.h>
#include <pmachine.h>
extern int errno;
int perrno;
int pfs_debug = 0;
main(argc, argv)
char *argv[];
{
char am_args[MAX_PTXT_LEN];
char path[MAX_VPATH];
char vcachebin[MAXPATHLEN];
char *lclfil;
char *method;
int am;
VLINK vl;
int pid;
union wait status;
int message_option = 0;
int avsflag = 0; /* If set - use active VS (no closure) */
char *debugflag = "-";
char *verboseflag = "-v";
argc--;argv++;
while (argc > 0 && *argv[0] == '-' && *(argv[0]+1) != '\0') {
switch (*(argv[0]+1)) {
case 'D':
pfs_debug = 1; /* Default debug level */
sscanf(argv[0],"-D%d",&pfs_debug);
debugflag = argv[0];
break;
case 'a':
avsflag++;
break;
case 'm':
message_option++;
break;
case 'q':
verboseflag = "-";
break;
case 'v':
verboseflag = "-v";
break;
default:
fprintf(stderr,
"Usage: vget [-a,-m,-q,-v] virtual-file [local-file]\n");
exit(1);
}
argc--; argv++;
}
/* The next argument must be the name of the file to retrieve */
/* within the virtual file system unless it is to extracted */
/* from a mail message */
if(argc < 1 && !message_option) {
fprintf(stderr,"Usage: vget [-a,-m,-q,-v] virtual-file [local-file]\n");
exit(1);
}
if (argc >= 1) strcpy(path,argv[0]);
/* if stdin is not a tty and OK to use closure */
/* then we have to extract closure info */
if(!avsflag && !isatty(0)) {
char *s;
s = readheader(stdin,"virtual-system-name:");
if(!s) {
fprintf(stderr,"vget: Can't find Virtual-System-Name.\n");
exit(1);
}
sprintf(path,"%s:",s);
if(message_option) {
s = readheader(stdin,"virtual-file-name:");
if(!s) {
fprintf(stderr,"vget: Can't find Virtual-file-name.\n");
exit(1);
}
strcat(path,s);
}
else strcat(path,argv[0]);
}
else if(message_option) {
fprintf(stderr,"vget: Can't find Virtual-file-name.\n");
exit(1);
}
/* If second name was not specified, derive it from first */
if(argc == (message_option ? 0 : 1)) {
char *p;
p = rindex(path,'/');
lclfil = (p != NULL) ? p + 1 : path;
}
/* Otherwise local file is the second name */
else lclfil = (message_option ? argv[0] : argv[1]);
vl = rd_vlink(path);
if(!vl) {
if(perrno == PSUCCESS) fprintf(stderr,"vget: File not found\n");
else perrmesg("vget: ", 0, NULL);
exit(1);
}
am = pget_am(vl,am_args,P_AM_AFTP | P_AM_FTP);
if(am == P_AM_AFTP) method = "AFTP";
else if (am == P_AM_FTP) method = "FTP";
else {
fprintf(stderr,"vget: Can't access file using anonymous ftp\n");
exit(1);
}
if(pwarn) pwarnmesg("WARNING: ",0,NULL);
pid = fork();
if (pid == 0) {
#ifdef USE_PATH
DISABLE_PFS(execlp("vcache","vcache",debugflag,verboseflag,
vl->host,vl->filename,lclfil,
method,am_args,0));
#endif USE_PATH
sprintf(vcachebin,"%s/vcache",P_BINARIES);
DISABLE_PFS(execl(vcachebin,"vcache",debugflag,verboseflag,
vl->host,vl->filename,lclfil,
method,am_args,0));
fprintf(stderr,"vget: exec failed for %s (errno=%d)\n",vcachebin,errno);
exit(1);
}
else wait(&status);
if(status.w_T.w_Retcode) {
fprintf(stderr,"vget: Retrieve failed\n");
exit(1);
}
exit(0);
}